Skip to content

fit-content: explain browser computation #39730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kannanwisen
Copy link

@kannanwisen kannanwisen commented May 29, 2025


Description

The fit-content operates using an intelligent clamping mechanism. It computes the size of an element using the following logic:

fit-content size=min(max-content,max(min-content,available-space))

Motivation

The current description of fit-content does not clearly explain how its sizing logic works internally. This update introduces a concise explanation of the clamping mechanism behind fit-content, including the formula used to compute the final size. It helps developers better understand how the function balances content size and available space, especially in responsive layouts.

Additional details

https://developer.mozilla.org/en-US/docs/Web/CSS/fit-content

Related issues and pull requests

@kannanwisen kannanwisen requested a review from a team as a code owner May 29, 2025 10:26
@kannanwisen kannanwisen requested review from estelle and removed request for a team May 29, 2025 10:26
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs size/xs [PR only] 0-5 LoC changed labels May 29, 2025
@@ -9,6 +9,10 @@ browser-compat: css.properties.width.fit-content

The **`fit-content`** keyword is equivalent to {{cssxref("fit-content_function", "fit-content(stretch)")}}. In practice, this means that the box will use the available space, but never more than {{cssxref("max-content")}}.

It calculates the size using the below equation:

fit-content size = min(max-content,max(min-content,available-space))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mdn-linter] reported by reviewdog 🐶

Suggested change
fit-content size = min(max-content,max(min-content,available-space))
fit-content size = min(max-content,max(min-content,available-space))

Copy link
Contributor

github-actions bot commented May 29, 2025

Preview URLs

(comment last updated: 2025-06-01 04:47:42)

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. I made some suggestions for the comment to better fit general MDN writing styles. To created "code" in markdown, add a back tick (`) before an after the text you want to style as code.

@estelle estelle changed the title Update index.md fit-content: epxlain browser computation May 29, 2025
@estelle estelle changed the title fit-content: epxlain browser computation fit-content: explain browser computation May 29, 2025
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Also, congratulations on your first merged MDN content PR. Welcome to he team!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:CSS Cascading Style Sheets docs size/xs [PR only] 0-5 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants